/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.aotoso.device.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.aotoso.device.entity.TestRes;
import com.thinkgem.jeesite.aotoso.device.service.TestResService;

/**
 * 设备采集到的数据列表Controller
 * @author youc
 * @version 2016-11-24
 */
@Controller
@RequestMapping(value = "${adminPath}/device/testRes")
public class TestResController extends BaseController {

	@Autowired
	private TestResService testResService;
	
	@ModelAttribute
	public TestRes get(@RequestParam(required=false) String id) {
		TestRes entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = testResService.get(id);
		}
		if (entity == null){
			entity = new TestRes();
		}
		return entity;
	}
	
	@RequiresPermissions("device:testRes:view")
	@RequestMapping(value = {"list", ""})
	public String list(TestRes testRes, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TestRes> page = testResService.findPage(new Page<TestRes>(request, response), testRes); 
		model.addAttribute("page", page);
		return "aotoso/device/testResList";
	}

	@RequiresPermissions("device:testRes:view")
	@RequestMapping(value = "form")
	public String form(TestRes testRes, Model model) {
		model.addAttribute("testRes", testRes);
		return "aotoso/device/testResForm";
	}

	@RequiresPermissions("device:testRes:edit")
	@RequestMapping(value = "save")
	public String save(TestRes testRes, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, testRes)){
			return form(testRes, model);
		}
		testResService.save(testRes);
		addMessage(redirectAttributes, "保存操作成功成功");
		return "redirect:"+Global.getAdminPath()+"/device/testRes/?repage";
	}
	
	@RequiresPermissions("device:testRes:edit")
	@RequestMapping(value = "delete")
	public String delete(TestRes testRes, RedirectAttributes redirectAttributes) {
		testResService.delete(testRes);
		addMessage(redirectAttributes, "删除操作成功成功");
		return "redirect:"+Global.getAdminPath()+"/device/testRes/?repage";
	}

}